<?php


namespace App\Api\Services;

use App\Api\Models\Goods as GoodsModels;
use App\Models\coupon\CmcPromotionCoupon;

class Goods
{

    // 查询该商品下的优惠券
    static public function getListGoodsCoupon($id,$memberId){
        if (empty($id)) throw new  \Exception('参数不能为空');
        // 调用模型查询商品所有优惠券
        $data = GoodsModels::getListGoodsCoupon($id);
        if (!$data) return [];
        // 数组分割
        $data = explode(',',$data);
        // 根据优惠券Id、用户id、商品id进行关联查询
        $result = CmcPromotionCoupon::getListGoodsCoupon($data,$memberId,$id);
        if (empty($result)) return [];
        return $result;
//        if (empty($result)){
//            return JsonService::fail('找不到数据','',config('code.HTTP_FAIL'));
//        }else{
//            return JsonService::success('查询成功',$result,config('code.HTTP_OK'));
//        }
    }
}